<template>
	<div class="view">
		<el-row :gutter="10">
			<el-col :span="5">
				<el-input v-model="search.nurseName" placeholder="请输入要查询的用户名"></el-input>
			</el-col>
			<el-col :span="19">
				<el-button type="primary" icon="el-icon-search" plain @click="searchData()">搜索</el-button>
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">添加用户</el-button>
				<!-- <el-button type="warning" icon="el-icon-delete" plain @click="batchdel()">批量删除</el-button> -->
			</el-col>
		</el-row>
		<el-table :data="result.tableData" class="eltable" style="width: 100%;font-size: 12px;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)"
		 @selection-change="handleSelectionChange">
			<!-- <el-table-column
        type="selection"
      > 
      </el-table-column> -->
			<el-table-column label="序号" width="40" prop="diaryId">
			</el-table-column>
			<el-table-column width="60" label="护士姓名" prop="nurseName">
			</el-table-column>

			<el-table-column width="120" label="护士工号" prop="nurseNumber">
			</el-table-column>
			<el-table-column width="200" label="工作内容" prop="jobContent">
			</el-table-column>
			<el-table-column width="90" label="提交时间" prop="submissionTime">
			</el-table-column> 

			<el-table-column label="状态" width="80">
				<template slot-scope="scope">
					<span v-if="scope.row.state==1">已审批</span>
					<span v-if="scope.row.state==0">未审批</span>
					<span v-if="scope.row.state!=0 && scope.row.state!=1 " >无效</span>
				</template>
			</el-table-column>

			<el-table-column width="120" label="审核意见" prop="auditOpinion">
			</el-table-column>
			<el-table-column width="60" label="审核人" prop="auditor">
			</el-table-column>
			<el-table-column width="150" label="审核时间" prop="auditTime">
			</el-table-column>

			<el-table-column label="操作" width="220px">
				<template slot-scope="scope">
					<template>
						<el-button size="mini" @click="handleEdit(scope.row.diaryId)">编辑</el-button>
						<el-button size="mini" type="danger" @click="handleDelete(scope.row.diaryId)">删除</el-button>
						<el-button size="mini" type="info" @click="handleAudit(scope.row.diaryId)">审核</el-button>
					</template>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination style="margin-top:10px;" background layout="prev, pager, next" :page-count="result.pages"
		 :current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>
		<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<WorkDiaryEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid"></WorkDiaryEdit>
		</el-dialog>
		<el-dialog :title="title" :visible.sync="audit" :close-on-click-modal="false" width="500px">
			<WorkDiaryAudit v-if="audit" :show.sync="audit" @getData="getData()" :auditid="auditid"></WorkDiaryAudit>
		</el-dialog>
	</div>
</template>

<script>
	import WorkDiaryEdit from '@/views/work_diary/edit.vue'
	import WorkDiaryAudit from '@/views/work_diary/audit.vue'
	export default {
		name: 'workDiary',
		data() {
			return {
				search: {
					nurseName: ''
				},
				query: {
					nurseName: '',
					current: 1,
					size: 4
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				audit: false,
				auditid: null,
				editid: null,
				selectedrow: [],
				title: ''
			}
		},
		components: {
			WorkDiaryEdit,
			WorkDiaryAudit
		},
		created() {
			this.getData()
			// console.log(this.getData())
		},
		methods: {
			getData() {
				this.axios.get('/workDiary/list', response => {
					// console.log(this.query.pageNo)
					this.result.tableData = response.obj.records
					// console.log(response.obj.total)
					// this.query.pageNo=response.obj.current
					this.result.pages = response.obj.pages

				}, this.query)
			},
			searchData() {
				// console.log(this.search)
				this.query.nurseName = this.search.nurseName
				console.log(this.search.nurseName)
				this.query.current = 1
				this.getData()
			},
			handleEdit(id) {
				this.title = '修改用户'
				this.editid = id
				this.show = true
			},
			add() {
				this.title = '添加用户'
				this.editid = null
				this.show = true
			},
			handleDelete(id) {
				this.axios.del('/workDiary/del/' + id, response => {
					this.getData()
				}, {
					id: id
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			},
			handleAudit(id) {
				this.title = '审核'
				this.auditid = id
				this.audit = true
			}

		}
	}
</script>
<style scoped>
	.view {
		font-size: 12px;

	}

	.eltable {
		width: 20px;
		padding: 0px;
	}

	.el-table-column {}
</style>
